package com.winchain.chainbill.bill.biz.transfer.cmd;

import com.shell.bee.acct.transaction.po.AcctTxRec;
import com.shell.bee.base.utils.DateUtil;
import com.shell.bee.base.utils.SpringContextUtil;
import com.shell.framework.command.CallbackContext;
import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICallback;
import com.shell.framework.command.ICommand;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.MessageSender;
import com.shell.governor.modules.message.keyword.RcvRevKeyword;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbXfe;
import com.winchain.chainbill.bill.biz.Bill;
import org.springframework.stereotype.Component;

@Component
public class BillXfeMsgCmd implements ICommand<Bill<CbXfe>>, ICallback<Bill<CbXfe>, AcctTxRec> {
	public boolean execute(CommandContext<Bill<CbXfe>> context) throws Exception {
		CbRec cbRec = ((Bill) context.getSource()).getRec();
		CbXfe cbXfe = (CbXfe) ((Bill) context.getSource()).getSource();

		String template = "MT01301";
		RcvRevKeyword keyWord = new RcvRevKeyword();
		keyWord.setBuyerNm(cbXfe.getBuyerNm());
		keyWord.setSndDate(DateUtil.parseDate(cbXfe.getCreateTime(), "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd"));
		keyWord.setBillAmt(String.valueOf(cbRec.getBillAmt()));
		keyWord.setExpDate(DateUtil.parseDate(cbRec.getExpDate(), "yyyyMMdd", "yyyy-MM-dd"));
		keyWord.setUrl(SpringContextUtil.getProperty("chainbill.website"));

		String senderId = CommonDataUtil.getUserId();
		String rcvId = cbXfe.getSellerId();

		MessageSender.sendMessageByTmpl(senderId, template, keyWord, rcvId);
		template = "MT02201";

		MessageSender.sendMessageByTmpl(senderId, template, keyWord, rcvId);
		return false;
	}

	public boolean callback(CallbackContext<Bill<CbXfe>, AcctTxRec> context) throws Exception {
		execute(context);
		return false;
	}
}
